package com.minimalist.lindi.mapper;

import com.minimalist.common.entity.lindi.po.LindiActivity;

import com.minimalist.common.entity.lindi.vo.activity.LindiActivityQueryVO;
import com.minimalist.common.entity.lindi.vo.activity.LindiActivityVO;
import com.mybatisflex.core.BaseMapper;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;

/**
 * 林地指标交易平台_活动内容表 映射层。
 *
 * @author 11987
 * @since 2025-06-12
 */
public interface LindiActivityMapper extends BaseMapper<LindiActivity>{

    /**
     * 根据活动ID查询活动
     *
     * @param activityId 活动ID
     * @return 活动
     */
    default LindiActivity selectActivityByActivityId(Long activityId){
        return selectOneByQuery(QueryWrapper.create()
                .eq(LindiActivity::getActivityId, activityId));
    }

    /**
     * 根据活动ID删除活动
     *
     * @param activityId 活动ID
     */
    default void deleteActivityByActivityId(Long activityId){
        deleteByQuery(QueryWrapper.create().eq(LindiActivity::getActivityId, activityId));
    }

    /**
     * 根据活动ID更新活动
     *
     * @param newActivity 活动
     */
    default void updateActivityByActivityId(LindiActivity newActivity){
        updateByQuery(newActivity, QueryWrapper.create()
                .eq(LindiActivity::getActivityId, newActivity.getActivityId()));
    }

    /**
     * 分页查询活动列表
     *
     * @param queryVO 活动查询条件
     * @return 活动分页列表
     */
    default Page<LindiActivity> selectPageActivityList(LindiActivityQueryVO queryVO){
        return paginate(queryVO.getPageNum(), queryVO.getPageSize(),
                QueryWrapper.create()
                        .select(LindiActivity::getId, LindiActivity::getActivityId, LindiActivity::getActivityTitle,
                                LindiActivity::getActivityContent, LindiActivity::getActivityTop, LindiActivity::getActivitySort,
                                LindiActivity::getStatus, LindiActivity::getCreateId, LindiActivity::getUpdateId,
                                LindiActivity::getCreateTime, LindiActivity::getUpdateTime)
                        .eq(LindiActivity::getStatus, queryVO.getStatus())
                        .like(LindiActivity::getActivityTitle, queryVO.getActivityTitle())
                        .orderBy(LindiActivity::getCreateTime, false));
    }

    /**
     * 前台网站分页查询活动列表
     *
     * @param queryVO 活动查询条件
     * @return 活动分页列表
     */
    default Page<LindiActivityVO> selectWebsiteActivityList(LindiActivityQueryVO queryVO){
        return paginateAs(queryVO.getPageNum(), queryVO.getPageSize(),
                QueryWrapper.create()
                        .select(LindiActivity::getId, LindiActivity::getActivityId, LindiActivity::getActivityTitle,
                                LindiActivity::getActivityTop, LindiActivity::getActivitySort, LindiActivity::getStatus,
                                LindiActivity::getCreateTime, LindiActivity::getUpdateTime)
                        .eq(LindiActivity::getStatus, queryVO.getStatus())
                        .like(LindiActivity::getActivityTitle, queryVO.getActivityTitle())
                        .orderBy(LindiActivity::getActivityTop, false)
                        .orderBy(LindiActivity::getActivitySort, true)
                        .orderBy(LindiActivity::getCreateTime, false), LindiActivityVO.class);
    }

    /**
     * 前台网站根据活动ID查询活动详情
     *
     * @param activityId 活动ID
     * @return 活动详情
     */
    default LindiActivity selectWebsiteActivityDetail(Long activityId){
        return selectOneByQuery(QueryWrapper.create()
                .eq(LindiActivity::getActivityId, activityId)
                .eq(LindiActivity::getStatus, 1));
    }
}
